package com.addcn.fog.view {
	import com.addcn.fog.core.Notifier;
	import com.addcn.fog.core.INotifier;	
	import flash.display.Sprite;
	/**
	 * 视图基类
	 * <p>
	 * <ul>
	 * <li>所有的视图继承于此类</li>
	 * <li>在子类中需要重写notificationsList,onDataChanged方法</li>
	 * </ul>
	 * 
	 */	
	public class View extends Sprite implements IView {
		//此视图需要监听的消息列表
		protected var m_notifications:Array = new Array();
		protected var m_notifier:INotifier = Notifier.getInstance();
		
		function View() : void {
			notificationsList();
		}
		
		/**
		 * 发送事件通知
		 * @param	notification<Class/String>：命令类或者每个 view 对应的相应的
		 * 										notifications 列表里的某一通知
		 * @param	data Object					传递的参数
		 */
		public function sendNotification(notification:Object, data:Object = null):void {
			m_notifier.sendNotification(notification, data);
		}
		
		public function set notifications(list:Array):void {
			m_notifications = list;
		}
		
		public function get notifications():Array {
			return m_notifications;
		}
		
		//子类覆盖此函数,添加子類所要關注的通知
		public function notificationsList() : void {
			notifications = []; //子类需要侦听的通知
		}
		
		//模型更新之后返回的数据，会 call 此函数
		public function onDataChanged(notification:String, data:Object = null):void {
			//在子类覆盖此函数
		}
		
		public function destroy(): void {
			//子類中覆蓋此方法,移除model前會調用該函數
		}
	}
}
